<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>角色提醒订阅</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){

        //销售审批订阅，有销售审批时发消息给用户
        var saleOrderAudit = new Ext.form.Checkbox({
          boxLabel : '销售订单审批提醒',
          name : 'sale_order_audit',
          listeners : { "check" : function(obj,ischecked){
          }}
        })

        var saleOrderDelivery = new Ext.form.Checkbox({
          boxLabel : '销售订单出库提醒',
          name : 'sale_order_delivery',
          listeners : { "check" : function(obj,ischecked){
          }}
        })

        var productStock = new Ext.form.Checkbox({
          boxLabel : '产品库存提醒',
          name : 'product_stock',
          listeners : { "check" : function(obj,ischecked){
          }}
        })

        var loanReturned = new Ext.form.Checkbox({
          boxLabel : '借货归还提醒',
          name : 'loan_returned',
          listeners : { "check" : function(obj,ischecked){
          }}
        })

        var roleId = new Ext.form.Hidden({
          name: 'id',
          value: '<%=params[:id]%>'
        });

        //提交按钮
        var submitButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            submitButton.setDisabled(true);
            if (subSysRemindForRoleFormPanel.form.isValid()) {
              subSysRemindForRoleFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    sysRemindForRoleWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  submitButton.enable();
                },
                failure: function(result, request){
                  submitButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              submitButton.enable();
            }
          }
        })
        
        var subSysRemindForRoleFormPanel = new Ext.form.FormPanel({
          labelWidth: 165,
          width: 400,
          labelAlign: 'right',
          frame : true,
          url: '/admin/updateSysRemindForRole',
          method: 'GET',
          items: [saleOrderAudit,saleOrderDelivery,productStock,loanReturned,roleId],
          buttons: [submitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                sysRemindForRoleWin.destroy();
              }
            }]
        });

        subSysRemindForRoleFormPanel.render('sub_sys_remind_for_role_form');
        //给每一个提醒赋予数据库内容
        <%if @sysRemindRegisters.length !=0%>
         <% @sysRemindRegisters.each do |sysRemindRegister| %>
           <% if sysRemindRegister.name == "销售订单审批" && sysRemindRegister.is_register == 1%>
             saleOrderAudit.setValue(true);
           <% elsif sysRemindRegister.name == "销售订单出库" && sysRemindRegister.is_register == 1%>
             saleOrderDelivery.setValue(true);
           <% elsif sysRemindRegister.name == "借货归还" && sysRemindRegister.is_register == 1%>
             loanReturned.setValue(true);
           <% elsif sysRemindRegister.name == "产品库存提醒" && sysRemindRegister.is_register == 1%>
             productStock.setValue(true);
           <%end%>
         <%end%>
        <%end%>
      })
    </script>
    <div id="sub_sys_remind_for_role_form"></div>
  </body>
</html>
